﻿
app.controller('EmergencyController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.GetNodeMenu = function (node) {
        mui.showLoading("正在加载..", "div");
        var hmenu = sessionStorage.getItem('EmergencyMenu');
        if (hmenu == null) {
            $http({
                method: 'POST',
                url: '../Account/GetMMenuList',
                data: { 'Node': node }
            })
                .success(function (ret) {
                    mui.hideLoading();
                    common.success($scope, null, ret);
                    if (ret.Code == 100) {
                        $scope.CheckMenuList = ret.Data;
                        sessionStorage.setItem("EmergencyMenu", JSON.stringify(ret.Data));
                    }
                    else {
                        mui.toast(ret.Msg);
                    }
                })
                .error(function (data, status, headers, config) {
                    mui.toast("请检查网络");
                });
        }
        else {
            $scope.CheckMenuList = JSON.parse(hmenu);
            mui.hideLoading();
        }
    }
    $scope.GetPlanTypeList = function () {
        $scope.PlanTypeList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlanTypeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });
    }
    $scope.AddDrillForm = function (model, EmpList) {
        if (model.PlaceId == null || model.PlaceId == "0") {
            alertify.alert("请选择场所");
            return false;
        }
        if (model.Summary == null || model.Summary == "") {
            alertify.alert("请填写总结概要");
            return false;
        }
        if (model.DrillTime == null || model.DrillTime == "") {
            alertify.alert("填写演练时间");
            return false;
        }
        if (model.TypeId == null || model.TypeId == "") {
            alertify.alert("请选择演练类型");
            return false;
        }
        if (model.DepartmentId == null || model.DepartmentId == "") {
            alertify.alert("请选择组织部门");
            return false;
        }
        if (model.Member == null || model.Member == "") {
            alertify.alert("请填写参加人员");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/AddDrillForm',
            data: { 'model': model, "EmployeeList": EmpList },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急演练添加成功！");

                    setTimeout(function () {
                        location.href = "DrillFormPageList";
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.EditDrillForm = function (model, page) {
        if (model.PlaceId == null || model.PlaceId == "0") {
            alertify.alert("请选择场所");
            return false;
        }
        if (model.Summary == null || model.Summary == "") {
            alertify.alert("请填写总结概要");
            return false;
        }
        if (model.DrillTime == null || model.DrillTime == "") {
            alertify.alert("填写演练时间");
            return false;
        }
        if (model.TypeId == null || model.TypeId == "") {
            alertify.alert("请选择演练类型");
            return false;
        }
        if (model.DepartmentId == null || model.DepartmentId == "") {
            alertify.alert("请选择组织部门");
            return false;
        }
        if (model.Member == null || model.Member == "") {
            alertify.alert("请填写参加人员");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/EditDrillForm',
            data: { 'model': model },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急演练修改成功！");

                    setTimeout(function () {
                        location.href = "DrillFormPageList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.MAddDrillForm = function (model) {
        if (model.PlaceId == null || model.PlaceId == "0") {
            mui.toast("请选择场所");
            return false;
        }
        if (model.Summary == null || model.Summary == "") {
            mui.toast("请填写总结概要");
            return false;
        }
        if (model.DrillTime == null || model.DrillTime == "") {
            mui.toast("填写演练时间");
            return false;
        }
        if (model.TypeId == null || model.TypeId == "") {
            mui.toast("请选择演练类型");
            return false;
        }
        if (model.DepartmentId == null || model.DepartmentId == "") {
            mui.toast("请选择组织部门");
            return false;
        }
        if (model.Member == null || model.Member == "") {
            mui.toast("请填写参加人员");
            return false;
        }
        $scope.Loading = true;
        model.DrillTime = $("#DrillTime").val();
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddDrillForm',
            data: { 'model': model, "FileList": $scope.FileList }
        })
            .success(function (ret) {
                $scope.Loading = false;
                if (ret.Code == 100) {
                    mui.toast("演练添加成功！");

                    setTimeout(function () {
                        location.href = "MDrillFormList";
                    }, 1000)
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.MEditEventReport = function (model) {
        if (model.PlaceId == null || model.PlaceId == "0") {
            mui.toast("请选择场所");
            return false;
        }
        if (model.Summary == null || model.Summary == "") {
            mui.toast("请填写总结概要");
            return false;
        }
        if (model.DrillTime == null || model.DrillTime == "") {
            mui.toast("填写演练时间");
            return false;
        }
        if (model.TypeId == null || model.TypeId == "") {
            mui.toast("请选择演练类型");
            return false;
        }
        if (model.DepartmentId == null || model.DepartmentId == "") {
            mui.toast("请选择组织部门");
            return false;
        }
        if (model.Member == null || model.Member == "") {
            mui.toast("请填写参加人员");
            return false;
        }
        $scope.Loading = true;
        model.DrillTime = $("#DrillTime").val();
        $http({
            method: 'POST',
            url: '../EmergencyPlan/EditDrillForm',
            data: { 'model': model, "FileList": $scope.FileList }
        })
            .success(function (ret) {
                $scope.Loading = false;
                if (ret.Code == 100) {
                    mui.toast("演练修改成功！");

                    setTimeout(function () {
                        location.href = "MDrillFormList";
                    }, 1000)
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }
    $scope.GetParkList = function () {
        $scope.ParkList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetParkList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.MGetPlaceList = function (id) {
        $scope.PlaceList = [];
        $http({
            method: 'POST',
            url: '../IssueReport/GetParkPlace',
            data: { "ParkId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceList = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });
    }
    $scope.GetPlaceList = function (control, id, defaultvalue) {
        if (id == null || id == "")
            return false;
        if (defaultvalue == null) {
            $("#" + control).html($compile('<option value="" selected>请选择场所</option>')($scope));
            $("#" + control).selectpicker('refresh');
        }
        $http({
            method: 'POST',
            url: '../IssueReport/GetParkPlace',
            data: { "ParkId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (defaultvalue != null) {
                            if (n.Id == defaultvalue)
                                $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                            else
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                        }
                        else {
                            $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                    $("#" + control).selectpicker('render');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
        if (defaultvalue != null) {
            $("#" + control).val(defaultvalue);
            $("#" + control).selectpicker('refresh');
            $("#" + control).selectpicker('render');
        }
    }



    $scope.GetDepartmentList = function (id) {
        $scope.DepartmentList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.DepartmentList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.refreshOption = function (control) {
        $("#" + control).selectpicker('refresh');
    }

    $scope.GetDrillFormPageList = function (model, page) {
        $scope.DrillFormList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetDrillFormPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.DrillFormList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }
    $scope.BindDepartmentList = function (control, defaultvalue) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (n.Id == defaultvalue)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteDrillForm = function (id, searchmodel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteDrillForm',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            $scope.AlertBox("删除成功！");
                            $scope.GetDrillFormPageList(searchmodel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.MDeleteDrillForm = function (id) {
        mui.confirm('确认删除该记录？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteDrillForm',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            mui.toast(ret.Msg);
                            $("#" + id).remove();
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });


            } else {
                //mui.toast("");
            }
        })
    }
    $scope.MGetPlaceList = function (id) {
        $scope.PlaceList = [];
        $http({
            method: 'POST',
            url: '../IssueReport/GetParkPlace',
            data: { "ParkId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceList = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });
    }

    $scope.MGetDrillForm = function (Id) {
        $scope.DrillFormDetail = {};
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetDrillForm',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {

                    $scope.DrillFormDetail = ret.Data;
                    $scope.GetDepartmentList();
                    $scope.DrillFormDetail.ParkId = $scope.DrillFormDetail.ParkId + "";
                    $scope.DrillFormDetail.PlaceId = $scope.DrillFormDetail.PlaceId + "";
                    $scope.DrillFormDetail.TypeId = $scope.DrillFormDetail.TypeId + "";
                    $scope.DrillFormDetail.DepartmentId = $scope.DrillFormDetail.DepartmentId + "";
                    $scope.DrillFormDetail.DrillTime = $filter('JSONDate')($scope.DrillFormDetail.DrillTime, 'yyyy-MM-dd HH:mm');
                    $scope.DrillFormDetail.CreateTime = $filter('JSONDate')($scope.DrillFormDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');

                    $scope.MGetPlaceList($scope.DrillFormDetail.ParkId);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDrillFormDetail = function (Id) {
        $scope.DrillFormDetail = {};
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetDrillForm',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.DrillFormDetail = ret.Data;
                    $scope.DrillFormDetail.ParkId = $scope.DrillFormDetail.ParkId + "";
                    $scope.DrillFormDetail.TypeId = $scope.DrillFormDetail.TypeId + "";
                    $scope.PlaceId = $scope.DrillFormDetail.PlaceId + "";
                    $scope.DrillFormDetail.DrillTime = $filter('JSONDate')($scope.DrillFormDetail.DrillTime, 'yyyy-MM-dd HH:mm');
                    $scope.DrillFormDetail.CreateTime = $filter('JSONDate')($scope.DrillFormDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.BindDepartmentList('dep_select', $scope.DrillFormDetail.DepartmentId);
                    $scope.GetPlaceList('placelist', $scope.DrillFormDetail.ParkId, $scope.DrillFormDetail.PlaceId);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteDrillFormFile = function (Id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteDrillFormFile',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].FileId == Id) {
                                    filelist.splice(i, 1);
                                }
                            }
                            $scope.AlertBox("删除成功！");
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.DeletePlanFormFile = function (Id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeletePlanFormFile',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].FileId == Id) {
                                    filelist.splice(i, 1);
                                }
                            }
                            $scope.AlertBox("删除成功！");
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.EditEventReport = function (model, page) {
        if (model.PlaceId == null || model.PlaceId == "0") {
            alertify.alert("请选择场所");
            return false;
        }
        if (model.EventContent == null || model.EventContent == "") {
            alertify.alert("填写事件内容");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../EventReport/EditEventReport',
            data: { 'model': model },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("事件报告修改成功！");
                    setTimeout(function () {
                        location.href = "EventReportPageList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Message);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.MGetDrillFormList = function (model, page) {
        if (page == 1) {
            $scope.DrillFormList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetDrillFormPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.DrillFormList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitDrillFormList = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: true,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetDrillFormList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetDrillFormList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }

    $scope.InitImgeUpload = function () {
        setTimeout(function () {
            for (var i = 0; i < $scope.ImageCount.length; i++) {
                var imagebox = "#imagebox_" + $scope.ImageCount[i];
                var dragImgUpload = new DragImgUpload(imagebox, {
                    callback: function (files) {
                        //回调函数，可以传递给后台等等
                        var file = files[0];
                        Upload.upload({
                            method: 'POST',
                            url: '../HiddenTrouble/UploadFormImage',
                            data: { "Category": 'Emergency/DrillForm' },
                            file: file
                        })
                            .success(function (ret) {
                                $scope.Submiting = false;
                                if (ret.Code == 100) {
                                    $scope.FileList.push(ret.Data);
                                    console.log($scope.FileList);

                                } else
                                    alertify.alert(ret.Msg);
                            })
                            .error(function (data, status, headers, config) {
                                common.error($scope);
                                mui.toast("请检查网络");
                            })
                    }
                }, "", $scope.ImageCount[i]);
            }
        }, 2000);
    }

    $scope.InitImgeUpload2 = function () {
        setTimeout(function () {
            for (var i = 0; i < $scope.ImageCount.length; i++) {
                var imagebox = "#imagebox_" + $scope.ImageCount[i];
                var dragImgUpload = new DragImgUpload(imagebox, {
                    callback: function (files) {
                        //回调函数，可以传递给后台等等
                        var file = files[0];
                        Upload.upload({
                            method: 'POST',
                            url: '../HiddenTrouble/UploadFormImage',
                            data: { "Category": 'Emergency/Evacuate' },
                            file: file
                        })
                            .success(function (ret) {
                                $scope.Submiting = false;
                                if (ret.Code == 100) {
                                    $scope.FileId = ret.Data;
                                    console.log($scope.FileList);

                                } else
                                    mui.toast(ret.Msg);
                            })
                            .error(function (data, status, headers, config) {
                                common.error($scope);
                                mui.toast("请检查网络");
                            })
                    }
                }, "", $scope.ImageCount[i]);
            }
        }, 2000);


    }

    $scope.InitImgeUpload3 = function () {
        setTimeout(function () {
            for (var i = 0; i < $scope.ImageCount.length; i++) {
                var imagebox = "#imagebox_" + $scope.ImageCount[i];
                var dragImgUpload = new DragImgUpload(imagebox, {
                    callback: function (files) {
                        //回调函数，可以传递给后台等等
                        var file = files[0];
                        Upload.upload({
                            method: 'POST',
                            url: '../Common/UploadFormImage',
                            data: { "Category": 'Emergency/PlanForm' },
                            file: file
                        })
                            .success(function (ret) {
                                $scope.Submiting = false;
                                if (ret.Code == 100) {
                                    $scope.FileList.push(ret.Data);
                                } else
                                    console.log
                            })
                            .error(function (data, status, headers, config) {
                                common.error($scope);
                            })
                    }
                }, "", $scope.ImageCount[i]);
            }
        }, 1000);

    }


    $scope.InitDatePicker = function (control) {
        (function ($) {
            $.init();
            var btns = $(control);
            btns.each(function (i, btn) {
                btn.addEventListener('tap', function () {
                    var _self = this;
                    if (_self.picker) {
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    } else {
                        var optionsJson = this.getAttribute('data-options') || '{}';
                        var options = JSON.parse(optionsJson);
                        var id = this.getAttribute('id');
                        _self.picker = new $.DtPicker(options);
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    }
                }, false);
            });
        })(mui);
    }

    $scope.GetEmployeeList = function (empno, selecedlist) {
        $scope.EmployeeList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmployeeList',
            data: { "EmployeeNoName": empno, "EmployeeList": selecedlist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.EmployeeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetAllPlace = function (control, defaultvalue) {
        $scope.PlaceList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlaceList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (defaultvalue != null) {
                            if (defaultvalue.includes(n.Id))
                                $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                            else
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                        }
                        else {
                            $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.PlaceName + "</option>")($scope));
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                    $("#" + control).selectpicker('render');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SelectEmployee = function (model) {
        $scope.ChoosenEmployeeList.push(model);
        $scope.EmployeeNoList.push(model.EmployeeNo);

        for (var i = 0; i < $scope.EmployeeList.length; i++) {
            var a = $scope.EmployeeList[i];
            if (a.EmployeeNo == model.EmployeeNo) {
                $scope.EmployeeList.splice(i, 1);
            }
        }
    }

    $scope.RemoveEmployee = function (model, searchmodel) {
        for (var i = 0; i < $scope.EmployeeNoList.length; i++) {
            var a = $scope.EmployeeNoList[i];
            if (a == model.EmployeeNo) {
                $scope.EmployeeNoList.splice(i, 1);
            }
        }
        for (var i = 0; i < $scope.ChoosenEmployeeList.length; i++) {
            var a = $scope.ChoosenEmployeeList[i];
            if (a.EmployeeNo == model.EmployeeNo) {
                $scope.ChoosenEmployeeList.splice(i, 1);
            }
        }
        $scope.GetEmployeeList(searchmodel, $scope.EmployeeNoList);
    }

    $scope.AddEvacuateForm = function (model, placename, page) {
        var files = document.querySelector('input[type=file]').files;
        if (files.length == 0) {
            alertify.alert("请上传应急疏散图！");
            return false;
        }
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/AddEvacuateForm',
            data: { 'model': model },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急疏散图添加成功！");
                    setTimeout(function () {
                        location.href = "EvacuateFileList?PlaceId=" + model.PlaceId + "&PlaceName=" + placename + "&page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.MAddEvacuateForm = function (model) {
        if ($scope.FileId == "") {
            alertify.alert("请上传应急疏散图！");
        }
        model.FileId = $scope.FileId;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/MAddEvacuateForm',
            data: { 'model': model }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    mui.toast("应急疏散图添加成功！");
                    setTimeout(function () {
                        location.href = "MEvacuateFileList?PlaceId=" + model.PlaceId;
                    }, 2000)
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetEvacuateList = function (id) {
        $scope.EvacuateList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEvacuateForm',
            data: { "PlaceId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.EvacuateList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.DeleteEvacuate = function (id) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteEvacuateForm',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            $scope.AlertBox("删除成功！");
                            $("#" + id).remove();
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.AddPlanForm = function (model) {
        if (model.ValidDate == null || model.ValidDate == "") {
            alertify.alert("填写有效期");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        model.Diagram = $scope.FileId;
        console.log(model);
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/AddPlanForm',
            data: { 'model': model, 'FileList': $scope.FileList },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急预案添加成功！");

                    setTimeout(function () {
                        location.href = "PlanFormPageList?page=1";
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetPlanFormPageList = function (model, page) {
        $scope.PlanFormList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanFormPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.PlanFormList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlanFormDetail = function (Id) {
        $scope.PlanFormDetail = {};
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanFormDetail',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlanFormDetail = ret.Data;
                    $scope.PlanFormDetail.DepartmentId = $scope.PlanFormDetail.DepartmentId + "";
                    $scope.BindDepartmentList('dep_select', $scope.PlanFormDetail.DepartmentId);
                    $scope.PlanFormDetail.ValidDate = $filter('JSONDate')($scope.PlanFormDetail.ValidDate, 'yyyy-MM-dd');
                    $scope.PlanFormDetail.CreateTime = $filter('JSONDate')($scope.PlanFormDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.GetAllPlace('place_select', $scope.PlanFormDetail.PlaceList);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.EditPlanForm = function (model, page) {
        if (model.DepartmentId == null || model.DepartmentId == "") {
            alertify.alert("请选择制定部门");
            return false;
        }
        if (model.ValidDate == null || model.ValidDate == "") {
            alertify.alert("填写有效期");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        if ($scope.FileId != null && $scope.FileId != '') {
            model.Diagram = $scope.FileId;
        }
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/EditPlanForm',
            data: { 'model': model, 'PlaceList': model.PlaceIdList },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急预案修改成功！");

                    setTimeout(function () {
                        location.href = "PlanFormPageList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.DeletePlanForm = function (id, searchmodel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeletePlanForm',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            $scope.AlertBox("删除成功！");
                            $scope.GetPlanFormPageList(searchmodel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }


    $scope.MGetPlanFormList = function (model, page) {
        if (page == 1) {
            $scope.PlanFormList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanFormPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.PlanFormList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitPlanFormList = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: true,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetPlanFormList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetPlanFormList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }

    $scope.MDeletePlanForm = function (id) {
        mui.confirm('确认删除该记录？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeletePlanForm',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            mui.toast(ret.Msg);
                            $("#" + id).remove();
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            } else {
                //mui.toast("");
            }
        })
    }
    $scope.ShowPicture = function (src) {
        $scope.IsPreview = true;
        $("#imgshow").attr("src", src);
    }
    $scope.ClosePreview = function () {
        $scope.IsPreview = false;
        $("#imgshow").attr("src", "");
    }
    $scope.MGetPlanFormDetail = function (Id) {
        $scope.PlanFormDetail = {};
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanDetail',
            data: { 'Id': Id }
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.PlanFormDetail = ret.Data;
                $scope.PlanFormDetail.ValidDate = $filter('JSONDate')($scope.PlanFormDetail.ValidDate, 'yyyy-MM-dd');
            }
            else {
                mui.toast(ret.Msg);
            }
        })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEmergencyTeamPageList = function (model, page) {
        $scope.TeamList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencyTeamPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.TeamList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEmergencyTeamList = function () {
        $scope.TeamList = [];
        mui.showLoading("正在加载..", "div");
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencyTeamList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                mui.hideLoading();
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.TeamList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.AddEmegencyTeam = function (model, page) {
        if (model.Name == null || model.Name == "0") {
            alertify.alert("请输入姓名");
            return false;
        }
        if (model.Department == null || model.Department == "") {
            alertify.alert("请输入部门");
            return false;
        }
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddEmergencyTeam',
            data: { 'model': model }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急队伍人员添加成功！");
                    setTimeout(function () {
                        location.href = "EmergencyTeamList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Message);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetEmergencyTeam = function (Id) {
        $scope.EditModel = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencyTeam',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.EditModel = ret.Data;
                    $scope.EditModel.CreateTime = $filter('JSONDate')($scope.EditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.UpdateEmegencyTeam = function (model, page) {
        if (model.Name == null || model.Name == "0") {
            alertify.alert("请输入姓名");
            return false;
        }
        if (model.Department == null || model.Department == "") {
            alertify.alert("请输入部门");
            return false;
        }
        $http({
            method: 'POST',
            url: '../EmergencyPlan/UpdateEmergencyTeam',
            data: { 'model': model }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急队伍人员修改成功！");
                    setTimeout(function () {
                        location.href = "EmergencyTeamList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Message);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.DeleteEmegencyTeam = function (id, searchmodel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteEmergencyTeam',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            $scope.AlertBox("删除成功！");
                            $scope.GetEmergencyTeamPageList(searchmodel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetPlanListByType = function () {
        $scope.PlanList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanFormByType'
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    $scope.PlanList = ret.Data;
                } else
                    alertify.alert(ret.Message);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.ShowPlanList = function (id) {
        $(".menu_body ").hide(100);
        $(".plan_" + id).toggle(200);

    }

    $scope.ShowPdf = function (url, title, model) {
        document.getElementById('pdfview').src = url;
        $("#planname").html(title);
        $scope.CurrentPlanForm = model;
    }
    $scope.ShowFlowChart = function () {
        if ($scope.CurrentPlanForm != null) {
            $scope.FlowChartList = $scope.CurrentPlanForm.FlowChartList;
            var htmlcontent = "";
            for (var i = 0; i < $scope.FlowChartList.length; i++) {
                htmlcontent += '<div class="item">';
                htmlcontent += '<div class="bcg" style="background-image: url(' + $scope.FlowChartList[i].FilePath + ');"></div>';
                htmlcontent += ' </div>';
            }
            $("#imagelist").html(htmlcontent);
            if ($scope.FlowChartList.length > 1) {
                $scope.InitImageView();
            }

        }
        $('#flowchart').addClass('open');
    }
    $scope.GetFactoryList = function () {
        $scope.FactoryList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetFactoryList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.FactoryList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetLocationList = function (id) {
        $scope.LocationList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetLocationList',
            data: { 'FactoryAreaId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.LocationList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SelectPosition = function (entity) {
        entity.X = Math.round($("#h_XAxis").val() * 100);
        entity.Y = Math.round($("#h_YAxis").val() * 100);
    }

    $scope.AddEventForm = function (model) {
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddEvent',
            data: { 'model': model }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急预案添加成功！");

                    setTimeout(function () {
                        location.href = "EventPageList?page=1";
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetCurrentEvent = function () {
        $scope.EventList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetProcessingEvent'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.EventList = ret.Data;

                    if ($scope.EventList.length > 0) {
                        $scope.EventModel = $scope.EventList[0];
                        $scope.GetEventFlowList($scope.EventModel.Id);
                        $scope.GetSuppliesList($scope.EventModel.FactoryAreaId);
                        $scope.GetEventPersonChart($scope.EventModel.Id);

                    }

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetEventFlowList = function (id) {
        $scope.FlowList = [];
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEventFlowList',
            data: { 'Id': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.FlowList = ret.Data;

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEventPageList = function (model, page) {
        $scope.EventFormList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEventPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.EventFormList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowWin = function (model, id, time) {
        model.IsComplete = "False";
        model.EventFormId = id;
        model.DealTime = time;
    }

    $scope.AddEventDealFlow = function (model) {
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddEventDealFlow',
            data: { 'model': model }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("处理流程添加成功！");

                    setTimeout(function () {
                        $("#btn_close").click();
                    }, 1000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }


    $scope.AddEmergencyTeam = function (model) {
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddEmergencyTeam',
            data: { 'model': model },
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetEmergencyTeamList = function (model, page) {
        $scope.TeamList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencyTeamPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.TeamList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetTeamList = function () {
        $scope.TeamList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencyTeamList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TeamList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.AddEmergencySupplies = function (model) {
        $http({
            method: 'POST',
            url: '../EmergencyPlan/AddEmergencySupplies',
            data: { 'model': model },
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetSuppliesList = function (factory) {
        $scope.SuppliesList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencySuppliesList',
            data: { 'FactoryAreaId': factory },
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.SuppliesList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEmergencySuppliesList = function (model, page) {
        $scope.SuppliesList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEmergencySuppliesPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.SuppliesList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEmergencyPlanDetail = function (Id) {
        $scope.EditModel = {};
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetPlanFormDetail',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.EditModel = ret.Data;
                    $scope.EditModel.CreateTime = $filter('JSONDate')($scope.EditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.EditModel.ValidDate = $filter('JSONDate')($scope.EditModel.ValidDate, 'yyyy-MM-dd');
                    $scope.EditModel.TypeId = $scope.EditModel.TypeId + '';
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.EditPlanForm = function (model, page) {
        if (model.ValidDate == null || model.ValidDate == "") {
            alertify.alert("填写有效期");
            return false;
        }
        var files = document.querySelector('input[type=file]').files;
        model.Diagram = $scope.FileId;
        console.log(model);
        Upload.upload({
            method: 'POST',
            url: '../EmergencyPlan/EditPlanForm',
            data: { 'model': model, 'FileList': $scope.FileList },
            file: files
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("应急预案修改成功！");

                    setTimeout(function () {
                        location.href = "PlanFormPageList?page=" + page;
                    }, 2000)
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.DeletePlanFile = function (formid, Id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../EmergencyPlan/DeleteEmergencyPlanFile',
                    data: { 'FormId': formid, 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].FileId == Id) {
                                    filelist.splice(i, 1);
                                }
                            }
                            alertify.alert("删除成功！");
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetMapLocation = function () {
        $scope.MapLocationList = [];
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetMapLocation'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.MapLocationList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.UpdateEventPerson = function (model) {
        $http({
            method: 'POST',
            url: '../EmergencyPlan/UpdateEventPerson',
            data: { 'model': model}
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("人员信息更新成功！");
                    $(".close").click();
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
            })
    }

    $scope.GetEventPerson = function (Id) {
        $scope.PersonModel = {};
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEventPerson',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.PersonModel = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.SetCurrentEvent = function (Id,model,page) {
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/SetCurrentEvent',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    $scope.GetEventPageList(model,page);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.GetEventPersonChart = function (Id) {
        $scope.PersonModel = {};
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../EmergencyPlan/GetEventPerson',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.PersonModel = ret.Data;
                    var datalist = [];
                    if ($scope.PersonModel != null) {
                        var obj = {
                            "name": "厂区员工",
                            "value": $scope.PersonModel.EmployeeCount
                        };
                        datalist.push(obj);

                        var obj2 = {
                            "name": "消防人员",
                            "value": $scope.PersonModel.FirefightersCount
                        };
                        datalist.push(obj2);

                        var obj3 = {
                            "name": "应急人员",
                            "value": $scope.PersonModel.EmergencyCount
                        };
                        datalist.push(obj3);
                    }
                    var mychart = echarts.init(document.getElementById('siteinfo'));
                    var option = {
                        color: [
                            "#3fb1e3",
                            "#6be6c1",
                            "#626c91",
                            "#a0a7e6",
                            "#c4ebad",
                            "#96dee8"
                        ],

                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'horizontal',
                            bottom: 5,
                            textStyle: {
                                color: 'white'
                            }
                        },

                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '60%'],
                                labelLine: {
                                    normal: {
                                        length: 3
                                    }
                                },
                                avoidLabelOverlap: false,
                                label: {
                                    formatter: '{b}{c}人',
                                    align: 'center',
                                    show: true,
                                    textStyle: {
                                        ellipsis: true, // 或者设置为 'truncate'
                                    },
                                    position: 'outside'
                                },
                                center: ['50%', '40%'],
                                emphasis: {
                                    label: {
                                        show: true,
                                        fontSize: 20,
                                        fontWeight: 'bold'
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist
                            }
                        ]
                    };
                    mychart.setOption(option);
                    mychart.resize();

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowBuildingStruct = function (src,model) {
        $('#structview').addClass('open');
        $("#location_map").attr("src", src);
        $scope.CurrentBuilding = model;
    }

    $scope.doMapMouse = function (type, index) {
        if ($scope.LastId != undefined) {
            var last = document.getElementById($scope.LastId);
            if (last != null) last.style = "display:none";
        }
        $scope.LastId = type + index;
        var id = type + index;
        var detail = document.getElementById(id);
        detail.style = "display:inline";
    }

    $scope.MouseLeave = function (type, index) {
        var id = type + index;
        var detail = document.getElementById(id);
        if (detail != null) {
            detail.style = "display:none";
        }
    }

    $scope.ChangeFactoryByArea = function (Id) {
        $scope.FactoryArea = Id;
    }
    $scope.InitImageView = function () {
        $('.coidea-3d-carousel').imagesLoaded({
            background: true
        }, function () {

            // hide loader
            $('.loader').addClass('is-loaded');


            // variables
            var timeline = new TimelineMax(),
                carousel = $(".coidea-3d-carousel"),
                boxes = $(".item"),
                stage = $(".stage"),
                $nav = $("#nav"),
                angle = 360 / 3;

            // set stage
            TweenMax.set(stage, {
                css: {
                    perspective: "86vw",
                    transformStyle: "preserve-3d"
                }
            });

            // set data rotation for each item
            boxes.each(function (index, element) {
                TweenMax.set(element, {
                    css: {
                        rotationY: index * angle
                    }
                });
                element.dataset.rotationY = index * angle;
            });

            // click on next item
            $nav.on("click", "#next", function () {

                timeline
                    .staggerTo($(boxes).find('.description-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo($(boxes).find('.headline-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo($(boxes).find('.discover-more-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo(boxes, 0.5, {
                        cycle: {
                            width: function (index, element) {
                                return "80%";
                            },
                            height: function (index, element) {
                                return "80%";
                            },
                            top: function (index, element) {
                                return "10%";
                            },
                            right: function (index, element) {
                                return "10%";
                            },
                            bottom: function (index, element) {
                                return "10%";
                            },
                            left: function (index, element) {
                                return "10%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo(boxes, 1, {
                        cycle: {
                            rotationY: function (index, element) {
                                var y1 = +element.dataset.rotationY;
                                var y2 = y1 - angle;
                                element.dataset.rotationY = y2;
                                return y2;
                            }
                        },
                        ease: Expo.easeInOut
                    }, 0, '+=0.25')
                    .staggerTo(boxes, 0.5, {
                        cycle: {
                            width: function (index, element) {
                                return "100%";
                            },
                            height: function (index, element) {
                                return "100%";
                            },
                            top: function (index, element) {
                                return "0%";
                            },
                            right: function (index, element) {
                                return "0%";
                            },
                            bottom: function (index, element) {
                                return "0%";
                            },
                            left: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '+=0.3')
                    .staggerTo($(boxes).find('.description-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo($(boxes).find('.headline-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo($(boxes).find('.discover-more-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
            });


            // click on prev item
            $nav.on("click", "#prev", function () {

                timeline
                    .staggerTo($(boxes).find('.description-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "-100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo($(boxes).find('.headline-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "-100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo($(boxes).find('.discover-more-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "-100%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo(boxes, 0.5, {
                        cycle: {
                            width: function (index, element) {
                                return "80%";
                            },
                            height: function (index, element) {
                                return "80%";
                            },
                            top: function (index, element) {
                                return "10%";
                            },
                            right: function (index, element) {
                                return "10%";
                            },
                            bottom: function (index, element) {
                                return "10%";
                            },
                            left: function (index, element) {
                                return "10%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo(boxes, 1, {
                        cycle: {
                            rotationY: function (index, element) {
                                var y1 = +element.dataset.rotationY;
                                var y2 = y1 + angle;
                                element.dataset.rotationY = y2;
                                return y2;
                            }
                        },
                        ease: Expo.easeInOut
                    }, 0, '+=0.25')
                    .staggerTo(boxes, 0.5, {
                        cycle: {
                            width: function (index, element) {
                                return "100%";
                            },
                            height: function (index, element) {
                                return "100%";
                            },
                            top: function (index, element) {
                                return "0%";
                            },
                            right: function (index, element) {
                                return "0%";
                            },
                            bottom: function (index, element) {
                                return "0%";
                            },
                            left: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '+=0.3')
                    .staggerTo($(boxes).find('.description-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0)
                    .staggerTo($(boxes).find('.headline-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5')
                    .staggerTo($(boxes).find('.discover-more-target'), 0.5, {
                        cycle: {
                            yPercent: function (index, element) {
                                return "0%";
                            }
                        },
                        ease: Circ.easeOut
                    }, 0, '-=0.5');
            });

        });
    }
});

app.filter('GetFactoryAreaName', function () {
    return function (text) {
        if (text == 1) {
            return "浦东";
        }
        else if (text == 2) {
            return "大场";
        }
    }
});